package com.kepler.social.domain.user.security;

import com.kepler.social.common.constants.Enums;
import com.kepler.social.common.utils.DateTimeUtil;
import com.kepler.social.usersecurity.dao.domain.UserEmail;
import com.kepler.social.usersecurity.dao.domain.UserMobilePhone;
import com.kepler.social.usersecurity.dao.domain.UserPassword;

import java.time.LocalDateTime;

public class UserSecurityFactory {

    public static UserSecurityAggregate toBeVerifiedOfEmail(String email, Long userId, String encryptedPassword) {
        long nowTime = DateTimeUtil.toMilli(LocalDateTime.now());
        return new UserSecurityAggregate(
                create(userId, encryptedPassword),
                UserEmail.builder()
                        .email(email).userId(userId).createdTime(nowTime)
                        .modifiedTime(nowTime).disuseTime(0L).state(Enums.UserEmailStateEnum.NOT_VERIFIED.code)
                        .build()
        );
    }

    public static UserSecurityAggregate toBeVerifiedOfMobilePhone(
            Integer countryCallingCode, Long mobilePhoneNumber, Long phoneId, Long userId, String encryptedPassword) {
        long nowTime = DateTimeUtil.toMilli(LocalDateTime.now());
        return new UserSecurityAggregate(
                create(userId, encryptedPassword),
                UserMobilePhone.builder()
                        .id(phoneId).userId(userId)
                        .countryCallingCode(countryCallingCode).phoneNumber(mobilePhoneNumber)
                        .state(Enums.UserMobilePhoneStateEnum.NOT_VERIFIED.code)
                        .createdTime(nowTime).modifiedTime(nowTime)
                        .disuseTime(0L)
                        .build()
        );
    }

    private static UserPassword create(Long userId, String encryptedPassword) {
        long nowTime = DateTimeUtil.toMilli(LocalDateTime.now());
        return UserPassword.builder()
                .userId(userId).password(encryptedPassword).createdTime(nowTime).modifiedTime(nowTime)
                .build();
    }


}
